package com.demo.design.behavioral.iterator.impl;

import com.demo.design.behavioral.iterator.Iterator;

import java.util.Collections;
import java.util.List;

public class IteratorSubject implements Iterator {

    private List<Object> objectList;
    private int index = -1;

    public IteratorSubject(List<Object> objectList) {
        this.objectList = objectList;
        if (objectList != null && objectList.size() != 0) {
            index = 0;
        }
    }

    @Override
    public Object getFirst() {
        index = 0;
        return objectList.get(index);
    }

    @Override
    public Object getNext() {
        return objectList.get(++index);
    }

    @Override
    public Object getLatest() {
        return objectList.get(--index);
    }

    @Override
    public Object hasNext() {
        if (objectList.size() > index +1) {
            return true;
        }
        return false;
    }
}
